Imports System.Xml.Serialization

Public Class Designer
    Inherits XEntityModelElementBase

    ''' <summary>Initializes an instance of the <see cref="Designer" /> class.
    ''' This is the default constructor for this class.</summary>
    Public Sub New()
        MyBase.New("Designer", EdmxXmlNamespace)
    End Sub

    ''' <summary>Initializes an instance of the <see cref="Designer" /> class.</summary>
    ''' <param name="other">An <see cref="System.Xml.Linq.XElement"/> object to copy from.</param>
    Public Sub New(ByVal other As XElement)
        MyBase.New(other)
    End Sub

    Private __diagrams As CanvasDesigner.DiagramCollection

    <AutoLoad()> _
    <XmlElement("Connection")> _
    Public Property Connection() As CanvasDesigner.Connection
        Get
            Return DirectCast(Me.Element(MyBase.Name.Namespace + "Connection"), EdmxEditor.CanvasDesigner.Connection)
        End Get
        Set(ByVal value As CanvasDesigner.Connection)
            If (DirectCast(value, XElement).Name <> (MyBase.Name.Namespace + "Connection")) Then
                Throw New ArgumentException("Invalid Element")
            End If
            If (Me.Connection IsNot Nothing) Then
                Me.Connection.Remove()
            End If
            Me.Add(New EdmxEditor.CanvasDesigner.Connection(value))
        End Set
    End Property

    <AutoLoad()> _
    <XmlElement("Options")> _
    Public Property Options() As CanvasDesigner.Options
        Get
            Return DirectCast(Me.Element(MyBase.Name.Namespace + "Options"), EdmxEditor.CanvasDesigner.Options)
        End Get
        Set(ByVal value As CanvasDesigner.Options)
            If (DirectCast(value, XElement).Name <> (MyBase.Name.Namespace + "Options")) Then
                Throw New ArgumentException("Invalid Element")
            End If
            If (Me.Options IsNot Nothing) Then
                Me.Options.Remove()
            End If
            Me.Add(New EdmxEditor.CanvasDesigner.Options(value))
        End Set
    End Property

    <AutoLoad()> _
    <XmlArrayItem(ElementName:="Diagram", Type:=GetType(CanvasDesigner.Diagram))> _
    Public ReadOnly Property Diagrams() As CanvasDesigner.DiagramCollection
        Get
            If (__diagrams Is Nothing) Then
                Dim name = MyBase.Name.Namespace + "Diagrams"
                Dim el = Me.Element(name)
                If (el Is Nothing) Then
                    el = New XElement(name)
                    Me.Add(el)
                End If
                __diagrams = New CanvasDesigner.DiagramCollection(el, "Diagram")
            End If
            Return __diagrams
        End Get
    End Property

End Class

